<template>
  <custom-navbar title="就业直播" :autoBack="true" leftIconColor="#303133" />
  <view class="p-24rpx bannerSwiper">
    <u-swiper indicator indicatorMode="dot" circular height="200" :list="list1" @change="e => current = e.current"
      imgMode="scaleToFill"></u-swiper>
  </view>
  <view class="text-30rpx font-middle color-#1d2129 ml-24rpx mt-36rpx mb-40rpx">直播间</view>
  <view class="list_contain">
    <scroll-view class="contain_w" :scroll-x="true" @scroll="scroll">
      <block v-for="(item,index) in videolist1" style="display: inline-block;" :key="index">
        <view class="list_contain_item">
          <image class="coverImg" :src="item.company.url_logo" mode=""></image>
          <view class="list_contain_item_title">{{item.title}}</view>
          <view class="list_contain_item_leftTopTips" v-if="item.status==1">
            <image src="@/static/images/icon_zbz.png" mode=""></image>
            直播中
          </view>
          <!-- <view class="list_contain_item_leftTopTips" style="background: #47B89A;" v-if="item.status==2">
            <image src="@/static/images/icon_hf.png" mode=""></image>
            回放
          </view> -->
          <!-- <view class="list_contain_item_leftTopTips" style="background: #1DAEE4;">
            <image src="@/static/images/icon_zbz.png" mode=""></image>
            预告
          </view> -->
        </view>
      </block>
    </scroll-view>
  </view>
  <view class="list_contain2">
    <view class="tab_list">
      <view v-for="(item,index) in tabData" :key="index" class="tab_list_default"
        :class="{'tab_list_active':currentTab == item.id }" @click="changeTab(item)">
        {{item.title}}
      </view>
    </view>
    <view class="list_item" v-for="(item,index) in videolist2" :key="index">
      <image :src="item.company.url_logo" mode="" class="coverImg"></image>
      <view class="list_item_info">
        <view class="list_item_info_left">
          <view class="">{{item.title}}</view>
          <view class="">{{item.company.name}}</view>
        </view>
        <view class="list_item_info_right">
          <view class="">点击进入</view>
          <view class="">{{item.start_time}}</view>
        </view>
      </view>
      <view class="list_contain_item_leftTopTips" v-if="item.type==1">
        <image src="@/static/images/icon_zbz.png" mode=""></image>
        直播中
      </view>
      <view class="list_contain_item_leftTopTips" style="background: #47B89A;" v-if="item.type==2">
        <image src="@/static/images/icon_hf.png" mode=""></image>
        回放
      </view>
      <view class="list_contain_item_leftTopTips" style="background: #1DAEE4;" v-if="item.type==3">
        <image src="@/static/images/icon_zbz.png" mode=""></image>
        预告
      </view>
    </view>
  </view>
</template>
<script setup>
  import {
    broadcast,
  } from '@/api/user';
  const list1 = [
    'https://cdn.uviewui.com/uview/swiper/swiper1.png',
    'https://cdn.uviewui.com/uview/swiper/swiper2.png',
    'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  ]
  const tabData = ref([{
    id: '1',
    title: '直播中'
  }, {
    id: '2',
    title: '预告'
  }, {
    id: '3',
    title: '回放'
  }]);
  const currentTab = ref('1');
  const page = ref(1);
  const videolist1 = ref([])
  const videolist2 = ref([])
  const changeTab = (item) => {
    currentTab.value = item.id
    page.value = 1
    videolist1.value = []
    videolist2.value = []
    getbroadcast()
  };
  onLoad(() => {
    getbroadcast()
  })
  onReachBottom(() => {
    page.value++
    getbroadcast()
  })
  const getbroadcast = async () => {
    // type 1直播中 2预告 3回放
    // 直播间
    let res = await broadcast({})
    videolist1.value = res.list
    console.log('直播列表返回', res.list);
    let res2 = await broadcast({
      type: currentTab.value,
      page: page.value
    })
    // console.log('直播列表返回', res);
    const now = new Date(); // 获取当前时间
    let dataList = res.list
    let arr = dataList.map((item, index) => {
      let startTime = new Date(item.start_time);
      let endTime = new Date(item.end_time);
      // 根据时间判断状态
      let type = '';
      if (now < startTime) {
        item['type'] = 2;
      } else if (now >= startTime && now <= endTime) {
        item['type'] = 1;
      } else if (now > endTime) {
        item['type'] = 3;
      }
      return item
    })
    console.log('arr', arr);
    if (arr) {
      if (page.value != 1) {
        videolist2.value = [...videolist2.value, ...arr]
      } else {
        videolist2.value = [...arr]
      }

    } else {
      if (page.value != 1) {
        page.value--
      }
    }
  }
</script>
<style scoped lang="scss">
  .bannerSwiper {
    ::v-deep .u-swiper-indicator__wrapper__dot {
      width: 22rpx !important;
      height: 6rpx !important;
      background: rgba(0, 0, 0, 0.25) !important;
      border-radius: 4rpx !important;
    }

    ::v-deep .u-swiper-indicator__wrapper__dot--active {
      width: 48rpx !important;
      height: 8rpx !important;
      background: #ffffff !important;
      border-radius: 4rpx !important;
      margin: 0 5px !important;
      transition: background-color 0.3s !important;
    }

    ::v-deep .u-swiper {
      height: 290rpx !important;
      border-radius: 36rpx !important;
    }

    .indicator {
      @include flex(row);
      justify-content: center;

      &__dot {

        width: 22rpx;
        height: 6rpx;
        background: #ffffff !important;
        border-radius: 4rpx !important;
        margin: 0 5px;
        transition: background-color 0.3s;

      }
    }
  }

  .list_contain {
    margin: 0rpx 0 0 24rpx;

    .contain_w {
      width: 100%;
      white-space: nowrap;
      overflow-x: scroll;
      overflow: auto;
      // display: block;
    }

    .list_contain_item {
      width: 268rpx;
      height: 360rpx;
      // border: 2rpx solid #dfdfdf;
      border-radius: 16rpx;
      margin-right: 20rpx;
      background: #ffffff;
      display: inline-block;
      position: relative;

      .coverImg {
        width: 268rpx;
        height: 240rpx;
        border-top-left-radius: 16rpx;
        border-top-right-radius: 16rpx;
      }

      .list_contain_item_title {
        width: 230rpx;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        margin: 20rpx 16rpx;
        font-size: 26rpx;
        font-family: PingFang SC, PingFang SC-Bold;
        font-weight: 700;
        text-align: left;
        color: #1d2129;
        letter-spacing: 0.16rpx;
      }

      .list_contain_item_leftTopTips {
        background: #fa4151;
        border-radius: 22rpx;
        padding: 0rpx 20rpx 2rpx 10rpx;
        box-sizing: border-box;
        position: absolute;
        left: 16rpx;
        top: 20rpx;
        font-size: 20rpx;
        font-family: PingFang SC, PingFang SC-Bold;
        font-weight: 700;
        color: #ffffff;
        display: flex;
        align-items: center;

        image {
          width: 44rpx;
          height: 44rpx;
        }
      }
    }
  }

  .list_contain2 {
    margin: 60rpx 24rpx 20rpx;

    .tab_list {
      display: flex;
      align-items: center;
      margin-bottom: 40rpx;
    }

    .tab_list_default {
      height: 42rpx;
      font-size: 30rpx;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: 400;
      text-align: left;
      color: #4e5968;
      margin-right: 40rpx;
    }

    .tab_list_active {
      height: 42rpx;
      font-size: 30rpx;
      font-family: PingFang SC, PingFang SC-Medium;
      font-weight: 700;
      text-align: left;
      color: #1d2129;
      margin-right: 40rpx;
    }

    .list_item {
      // width: 702rpx;
      // height: 344rpx;
      background: #ffffff;
      border-radius: 24rpx;
      box-shadow: 0rpx 6rpx 20rpx 0rpx rgba(235, 235, 235, 0.50);
      margin-bottom: 30rpx;
      padding: 0 0 24rpx;
      position: relative;

      .coverImg {
        width: 702rpx;
        height: 260rpx;
        border-top-left-radius: 24rpx;
        border-top-right-radius: 24rpx;
      }

      .list_item_info {
        padding: 20rpx 24rpx 0;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .list_item_info_left {
          view:nth-child(1) {
            height: 34rpx;
            font-size: 24rpx;
            font-family: PingFang SC, PingFang SC-Medium;
            font-weight: 500;
            text-align: left;
            color: #4e5969;
            letter-spacing: 0.14rpx;
            margin-bottom: 12rpx;
          }

          view:nth-child(2) {
            font-size: 24rpx;
            font-family: PingFang SC, PingFang SC-Regular;
            font-weight: 400;
            text-align: left;
            color: #666666;

            image {
              width: 34rpx;
              height: 34rpx;
            }
          }
        }

        .list_item_info_right {
          view:nth-child(1) {
            width: 112rpx;
            height: 36rpx;
            background: rgba(78, 89, 105, 0.1);
            border-radius: 18rpx;
            font-size: 20rpx;
            font-family: PingFang SC, PingFang SC-Bold;
            font-weight: 700;
            text-align: center;
            line-height: 36rpx;
            color: #333;
            margin-bottom: 12rpx;
          }

          view:nth-child(2) {
            font-size: 20rpx;
            font-family: PingFang SC, PingFang SC-Regular;
            font-weight: 400;
            color: #bebebe;

          }
        }
      }

      .list_contain_item_leftTopTips {
        background: #fa4151;
        border-radius: 22rpx;
        padding: 0rpx 20rpx 2rpx 10rpx;
        box-sizing: border-box;
        position: absolute;
        left: 16rpx;
        top: 20rpx;
        font-size: 20rpx;
        font-family: PingFang SC, PingFang SC-Bold;
        font-weight: 700;
        color: #ffffff;
        display: flex;
        align-items: center;

        image {
          width: 44rpx;
          height: 44rpx;
        }
      }
    }
  }
</style>
